﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
//using Aleastur.Framework.Mvc.Html;

namespace System.Web.Mvc.Html
{
    public static class HtmlHelperActionLinkExtensions
    {

        public static IDisposable BeginActionLink(this HtmlHelper helper, string actionName)
        {
            return BeginActionLink(helper, actionName, null);
        }

        public static IDisposable BeginActionLink(this HtmlHelper helper, string actionName, string controllerName)
        {
            return BeginActionLink(helper, actionName, controllerName, null);
        }

        public static IDisposable BeginActionLink(this HtmlHelper helper, string actionName, string controllerName, object routeValues)
        {
            return BeginActionLink(helper, actionName, controllerName, routeValues, null);
        }

        public static IDisposable BeginActionLink(this HtmlHelper helper, string actionName, object routeValues)
        {
            return BeginActionLink(helper, actionName, null, routeValues);
        }

        public static IDisposable BeginActionLink(this HtmlHelper helper, string actionName, string controllerName, object routeValues, object htmlAttributes)
        {
            UrlHelper Url = new UrlHelper(helper.ViewContext.RequestContext);

            TagBuilder a = new TagBuilder("a");
            a.Attributes["href"] = Url.Action(actionName, controllerName, routeValues);

            if (htmlAttributes != null)
            {
                RouteValueDictionary attrDict = new RouteValueDictionary(htmlAttributes);
                a.MergeAttributes(attrDict, true);
            }

            HtmlViewWriterExtensions.Write(helper, a.ToString(TagRenderMode.StartTag));

            return helper.BeginDisposable(h => HtmlViewWriterExtensions.Write(h,a.ToString(TagRenderMode.EndTag)));
        }

       
    }
}
